import {Request} from "express";
import Operator from "../operator/Operator";
import OperateArgs from "../operator/OperateArgs";
import {RC} from "../config/RC";

abstract class RequestProcess {
    protected req !: Request; // !: 表示req对象一定有值，否则报错
    protected args !: OperateArgs;
    operator_plan !: Operator;

    constructor(req: Request) {
        this.req = req;
    }

    /**
     * 模板方法
     * 1. 参数生成
     * 2. 策略生成
     * 3. 执行
     * 4. 返回结果
     */
    public async process() {
        this.args_generate();
        this.operator_plan_generate();
        return await this.operator_plan.execute().then(
            (rc) =>{
                return this.writeResult(rc);
            }
        );

    }
    public abstract args_generate(): void ;

    public abstract operator_plan_generate(): void;

    public abstract writeResult(rc: RC): Object;

    public getOperateArgs(): OperateArgs {
        return this.args;
    }
}

export default RequestProcess;